<script setup>

import {useUserStore} from "../store/userStore.js";
let onSubmit = async () => {
  console.log(useUserStore().search_type);
  await useUserStore().updateUser()
  if (useUserStore().search_type === '学号') {
    await useUserStore().updateStudents(1, 5)
  } else if (useUserStore().search_type === '教师号') {
    await useUserStore().updateTeachers(1, 5)
  } else if (useUserStore().search_type === '管理员') {
    await useUserStore().updateAdmins(1, 5)
  }
  await useUserStore().getUserInfo()
}
</script>

<template>
  <!-- Put this part before </body> tag -->
  <div class="modal text-base-content" role="dialog" id="my_modal_8">
    <div class="modal-box">
      <h3 class="text-lg font-bold">编辑</h3>

      <fieldset class="fieldset">
        <legend class="fieldset-legend">{{ useUserStore().search_type}}</legend>
        <input type="text" :placeholder="useUserStore().search_type" class="input" v-model="useUserStore().currentUser.username"/>
      </fieldset>

      <fieldset class="fieldset" v-if="useUserStore().search_type==='账户'">
        <legend class="fieldset-legend">密码</legend>
        <input type="text" placeholder="密码" class="input" v-model="useUserStore().currentUser.password"/>
      </fieldset>

      <fieldset class="fieldset">
        <legend class="fieldset-legend">姓名</legend>
        <input type="text" placeholder="姓名" class="input" v-model="useUserStore().currentUser.realName"/>
      </fieldset>


      <fieldset class="fieldset">
        <legend class="fieldset-legend">性别</legend>
        <input type="text" placeholder="性别" class="input" v-model="useUserStore().currentUser.gender"/>
      </fieldset>

      <fieldset class="fieldset">
        <legend class="fieldset-legend">手机</legend>
        <input type="text" placeholder="手机" class="input" v-model="useUserStore().currentUser.phone"/>
      </fieldset>

      <fieldset class="fieldset">
        <legend class="fieldset-legend">邮箱</legend>
        <input type="text" placeholder="邮箱" class="input" v-model="useUserStore().currentUser.email"/>
      </fieldset>

      <br>
      <div class="modal-action">
        <a href="#" class="btn btn-accent" @click="onSubmit">完成</a>
        <a href="#" class="btn btn-ghost">取消</a>
      </div>
    </div>
  </div>
</template>

<style scoped>

</style>